﻿function jsonData (txt) {
    var long = txt.split("(")[1];
    long = long.split(")")[0];
    var date = new Date();
    date.setTime(long);
    return date.getFullYear() + "/" + getMonth(date) + "/" + getDay(date);
}

function getMonth(date) {
    var month = "";
    month = date.getMonth() + 1;
    if (month < 10) {
        month = "0" + month;
    }
    return month;
} 

function getDay(date) {
    var day = "";
    day = date.getDate();
    if (day < 10) {
        day = "0" + day;
    }
    return day;
}

function getPost (url, data, success, options) {
    options = options || {};
    data = data || {};
    return $.ajax({
        type: options.type || 'post',
        dataType: options.dataType || 'json',
        data: data,
        url: url,
        success: function (res) {
            if (res.status === 0) {
                success && success(res);
            } else {
                layer.msg(res.msg || res.code, { shift: 6 });
            }
        }, error: function (e) {
            options.error || layer.msg('请求异常，请重试', { shift: 6 });
        }
    });
}

function getPost2(url, data, success) {
    data = data || {};
    return $.ajax({
        type: 'post',
        dataType: 'json',
        data: data,
        url: url,
        success: function (res) {
            if (res.success === true) {
                success && success(res.data);
            } else {
                layer.msg(res.msg, { shift: 6 });
            }
        }, error: function () {
            layer.msg('请求异常，请重试', { shift: 6 });
        }
    });
}

function redirect(ctr, view, id, no,kind) {
    if (IsEmpty(ctr) || IsEmpty(view)) {
        return;
    }
    id = id || 0,
    no = no || "";   
    location.href = '/home/RedirectToPage?ctr='+ctr+'&view='+view+'&Id='+id+"&no="+no+"&kind="+kind;
}

function IsEmpty(obj) {
    if (obj == undefined || obj == null || obj == "" || obj.trim() == "") {
        return true;
    } else {
        return false;
    }
}

//把 &#编码转换成字符
function uncode(str) {
    return str.replace(/&#(x)?([^&]{1,5});?/g, function (a, b, c) {
        return String.fromCharCode(parseInt(c, b ? 16 : 10));
    });

}

//把字符转换成 &#编码
function encode(str) {
    var a = [], i = 0;
    for (; i < str.length;) a[i] = str.charCodeAt(i++);
    return "&#" + a.join(";&#") + ";";
}